 *********************************************************************************
/*    Create scatter plot for revenue, cost, and revenue/cost by income		*/
*********************************************************************************
clear all

* Set directories 
adopath + "${oi_home}/Research files/ado"

* File paths
local datapath "${mvpf_audits}/data/cleaned" 
local graphpath "${graphpath}"  

* Waterfall chart to produce
local useloop = 1 // =1 for operational, =2 for ops + corr

* Version of fig to produce 
global version  ${version} // paper or slides

* Other formatting
if "${version}" == "slides" {
	global title "title(" ", size(vhuge))"
	global img wmf
	graph set window fontface "Arial"
	global title "title(" ", size(vhuge))"
	global axis_size "" //xsize(6.5) ysize(4)" // makes figure wider
}

else if "${version}" == "paper" {
	global title "title("")"
	global img pdf
	graph set window fontface "LMRoman10-Regular"
	global title " "
	global axis_size " " // makes figure wider
}

* create waterfall for each exam type
	if `useloop'== 1 { 
		local hetlist `""if exam_type_pooled==1" "'
		local hettexts `" "Operational" "'
		local hetlabs `""ops" "'
	}


/*------------------------------------------------------------------------------
Figure: Average auditor hours and wage by income
------------------------------------------------------------------------------*/

use "${mvpf_audits}/data/figures_rep/ap8.dta", clear

*preserve
	* set y-axis label, title, and figure name
	local ylab = "Average value"
	lab val ${inc}_pctl ${inc}_pctl_label
	
	* xtitle
	if "${inc}"=="agi" global xtitle = "AGI percentile group"
	if "${inc}"=="tpi" global xtitle = "TPI percentile group"

	* Preferences 
	local symbsize medsmall
	local textsize vsmall
	
	*** Subgroup figure
	local fig_name = "scatter_hours_wages_${inc}"
	
	local lb = 10
	local ub = 60 // round(`max', 100)
	local int = 10 // (`ub' - `lb')/5		
	local lb_f : di %02.1f `lb'
	local ub_f : di %02.1f `ub'
	
	global oh_color = "240 128 128"

	tw  (scatter hours_future ${inc}_pctl if inrange(${inc}_pctl, 1, 22) & exam_type_pooled==1, ///
		mcolor("${oh_color}") msymbol(O) msize(`symbsize')) ///
		(scatter wage ${inc}_pctl if inrange(${inc}_pctl, 1, 22) & exam_type_pooled==1, ///
		mcolor(cranberry) msymbol(T) msize(small)) ///
		, ///
		ylabel(`lb'(`int')`ub', nogrid format(%9.0fc)) yscale(r(`lb_f' `ub_f')) ///
		ytitle("`ylab'") xtitle("${xtitle}")   ///
		legend(order(2 1)  lab(1 "Hours per audit") lab(2 "Auditor Wage ($/hour)") ///
		ring(0) pos(11) col(1) symxsize(*3.5) region(lcolor())) ///
		${title} ${axis_size} ///
		xscale(r(1 22))  ///
		xlabel(1(1)22, value labsize(small) tl(.5) nogrid angle(45) )  
	graph export "`graphpath'/`fig_name'_ops.wmf", as(wmf) replace
